USE [mmit]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Transactions_Account]') AND parent_object_id = OBJECT_ID(N'[dbo].[Transactions]'))
ALTER TABLE [dbo].[Transactions] DROP CONSTRAINT [FK_Transactions_Account]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Transactions_Account1]') AND parent_object_id = OBJECT_ID(N'[dbo].[Transactions]'))
ALTER TABLE [dbo].[Transactions] DROP CONSTRAINT [FK_Transactions_Account1]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Transactions_Account2]') AND parent_object_id = OBJECT_ID(N'[dbo].[Transactions]'))
ALTER TABLE [dbo].[Transactions] DROP CONSTRAINT [FK_Transactions_Account2]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Transactions_TransactionTypes1]') AND parent_object_id = OBJECT_ID(N'[dbo].[Transactions]'))
ALTER TABLE [dbo].[Transactions] DROP CONSTRAINT [FK_Transactions_TransactionTypes1]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Account_Customers]') AND parent_object_id = OBJECT_ID(N'[dbo].[Account]'))
ALTER TABLE [dbo].[Account] DROP CONSTRAINT [FK_Account_Customers]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Rule_Account]') AND parent_object_id = OBJECT_ID(N'[dbo].[Rule]'))
ALTER TABLE [dbo].[Rule] DROP CONSTRAINT [FK_Rule_Account]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Rule_Rule]') AND parent_object_id = OBJECT_ID(N'[dbo].[Rule]'))
ALTER TABLE [dbo].[Rule] DROP CONSTRAINT [FK_Rule_Rule]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Rule_TransactionTypes]') AND parent_object_id = OBJECT_ID(N'[dbo].[Rule]'))
ALTER TABLE [dbo].[Rule] DROP CONSTRAINT [FK_Rule_TransactionTypes]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Charge_AccountType]') AND parent_object_id = OBJECT_ID(N'[dbo].[Charge]'))
ALTER TABLE [dbo].[Charge] DROP CONSTRAINT [FK_Charge_AccountType]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Charge_TransactionTypes]') AND parent_object_id = OBJECT_ID(N'[dbo].[Charge]'))
ALTER TABLE [dbo].[Charge] DROP CONSTRAINT [FK_Charge_TransactionTypes]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RoleAccount_Account]') AND parent_object_id = OBJECT_ID(N'[dbo].[RoleAccount]'))
ALTER TABLE [dbo].[RoleAccount] DROP CONSTRAINT [FK_RoleAccount_Account]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RoleAccount_Role]') AND parent_object_id = OBJECT_ID(N'[dbo].[RoleAccount]'))
ALTER TABLE [dbo].[RoleAccount] DROP CONSTRAINT [FK_RoleAccount_Role]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RoleTransactiontype_Role]') AND parent_object_id = OBJECT_ID(N'[dbo].[RoleTransactiontype]'))
ALTER TABLE [dbo].[RoleTransactiontype] DROP CONSTRAINT [FK_RoleTransactiontype_Role]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RoleTransactiontype_TransactionTypes]') AND parent_object_id = OBJECT_ID(N'[dbo].[RoleTransactiontype]'))
ALTER TABLE [dbo].[RoleTransactiontype] DROP CONSTRAINT [FK_RoleTransactiontype_TransactionTypes]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TransactionCharge_Account]') AND parent_object_id = OBJECT_ID(N'[dbo].[TransactionCharge]'))
ALTER TABLE [dbo].[TransactionCharge] DROP CONSTRAINT [FK_TransactionCharge_Account]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TransactionCharge_Account1]') AND parent_object_id = OBJECT_ID(N'[dbo].[TransactionCharge]'))
ALTER TABLE [dbo].[TransactionCharge] DROP CONSTRAINT [FK_TransactionCharge_Account1]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TransactionCharge_Transactions]') AND parent_object_id = OBJECT_ID(N'[dbo].[TransactionCharge]'))
ALTER TABLE [dbo].[TransactionCharge] DROP CONSTRAINT [FK_TransactionCharge_Transactions]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Vouchers_Account]') AND parent_object_id = OBJECT_ID(N'[dbo].[Vouchers]'))
ALTER TABLE [dbo].[Vouchers] DROP CONSTRAINT [FK_Vouchers_Account]
GO

USE [mmit]
GO

/****** Object:  Table [dbo].[Transactions]    Script Date: 01/12/2012 13:43:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Transactions]') AND type in (N'U'))
DROP TABLE [dbo].[Transactions]
GO

/****** Object:  Table [dbo].[Account]    Script Date: 01/12/2012 13:43:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Account]') AND type in (N'U'))
DROP TABLE [dbo].[Account]
GO

/****** Object:  Table [dbo].[Rule]    Script Date: 01/12/2012 13:43:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Rule]') AND type in (N'U'))
DROP TABLE [dbo].[Rule]
GO

/****** Object:  Table [dbo].[Charge]    Script Date: 01/12/2012 13:43:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Charge]') AND type in (N'U'))
DROP TABLE [dbo].[Charge]
GO

/****** Object:  Table [dbo].[RoleAccount]    Script Date: 01/12/2012 13:43:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RoleAccount]') AND type in (N'U'))
DROP TABLE [dbo].[RoleAccount]
GO

/****** Object:  Table [dbo].[Role]    Script Date: 01/12/2012 13:43:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Role]') AND type in (N'U'))
DROP TABLE [dbo].[Role]
GO

/****** Object:  Table [dbo].[TransactionTypes]    Script Date: 01/12/2012 13:43:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TransactionTypes]') AND type in (N'U'))
DROP TABLE [dbo].[TransactionTypes]
GO

/****** Object:  Table [dbo].[RoleTransactiontype]    Script Date: 01/12/2012 13:43:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RoleTransactiontype]') AND type in (N'U'))
DROP TABLE [dbo].[RoleTransactiontype]
GO

/****** Object:  Table [dbo].[TransactionCharge]    Script Date: 01/12/2012 13:43:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TransactionCharge]') AND type in (N'U'))
DROP TABLE [dbo].[TransactionCharge]
GO

/****** Object:  Table [dbo].[AccountType]    Script Date: 01/12/2012 13:43:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AccountType]') AND type in (N'U'))
DROP TABLE [dbo].[AccountType]
GO

/****** Object:  Table [dbo].[Customers]    Script Date: 01/12/2012 13:43:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Customers]') AND type in (N'U'))
DROP TABLE [dbo].[Customers]
GO

/****** Object:  Table [dbo].[Vouchers]    Script Date: 01/12/2012 13:43:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Vouchers]') AND type in (N'U'))
DROP TABLE [dbo].[Vouchers]
GO

USE [mmit]
GO

/****** Object:  Table [dbo].[Transactions]    Script Date: 01/12/2012 13:43:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Transactions](
	[TransactionId] [bigint] IDENTITY(1,1) NOT NULL,
	[TransactionCode] [varchar](50) NULL,
	[TransactionTypeId] [int] NULL,
	[Amount] [float] NULL,
	[Status] [varchar](50) NULL,
	[TimeFinalised] [datetime] NULL,
	[TimeInitiated] [datetime] NULL,
	[TimeProcessed] [datetime] NULL,
	[AuthorisationId] [int] NULL,
	[ParentId] [int] NULL,
	[LastUpdate] [datetime] NULL,
	[ExpiryDate] [datetime] NULL,
	[RecipientId] [int] NULL,
	[SenderId] [int] NULL,
 CONSTRAINT [PK_Transactions] PRIMARY KEY CLUSTERED 
(
	[TransactionId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [mmit]
GO

/****** Object:  Table [dbo].[Account]    Script Date: 01/12/2012 13:43:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Account](
	[AccountId] [int] IDENTITY(1,1) NOT NULL,
	[Name] [varchar](max) NULL,
	[AccountTypeId] [int] NULL,
	[Status] [int] NULL,
	[ActualBalance] [float] NULL,
	[AvailableBalance] [float] NULL,
	[CustomerId] [int] NULL,
	[TimeStamp] [timestamp] NULL,
 CONSTRAINT [PK_Account] PRIMARY KEY CLUSTERED 
(
	[AccountId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [mmit]
GO

/****** Object:  Table [dbo].[Rule]    Script Date: 01/12/2012 13:43:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Rule](
	[RuleId] [int] IDENTITY(1,1) NOT NULL,
	[TransactionAmount] [float] NULL,
	[TargetAccountId] [int] NULL,
	[TargetTransactionTypeId] [int] NULL,
	[TargetRoleId] [int] NULL,
	[NumberofTransactions] [int] NULL,
	[WindowPeriodInHours] [int] NULL,
	[MaxBalance] [float] NULL,
	[MinBalance] [float] NULL,
 CONSTRAINT [PK_Rule] PRIMARY KEY CLUSTERED 
(
	[RuleId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [mmit]
GO

/****** Object:  Table [dbo].[Charge]    Script Date: 01/12/2012 13:43:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Charge](
	[ChargeId] [int] IDENTITY(1,1) NOT NULL,
	[Name] [varchar](250) NULL,
	[MinAmount] [float] NULL,
	[MaxAmount] [float] NULL,
	[TransactionTypeId] [int] NULL,
	[AccountTypeId] [int] NULL,
	[Status] [int] NULL,
	[PercentageAmount] [decimal](18, 0) NULL,
	[FixedAmount] [float] NULL,
 CONSTRAINT [PK_Charge] PRIMARY KEY CLUSTERED 
(
	[ChargeId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [mmit]
GO

/****** Object:  Table [dbo].[RoleAccount]    Script Date: 01/12/2012 13:43:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[RoleAccount](
	[RoleAccountId] [int] IDENTITY(1,1) NOT NULL,
	[RoleId] [int] NULL,
	[AccountId] [int] NULL,
	[Status] [int] NULL,
 CONSTRAINT [PK_RoleAccount] PRIMARY KEY CLUSTERED 
(
	[RoleAccountId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [mmit]
GO

/****** Object:  Table [dbo].[Role]    Script Date: 01/12/2012 13:43:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Role](
	[RoleId] [int] IDENTITY(1,1) NOT NULL,
	[Name] [varchar](50) NULL,
 CONSTRAINT [PK_Role] PRIMARY KEY CLUSTERED 
(
	[RoleId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [mmit]
GO

/****** Object:  Table [dbo].[TransactionTypes]    Script Date: 01/12/2012 13:43:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[TransactionTypes](
	[TransactionTypeId] [int] IDENTITY(1,1) NOT NULL,
	[TransactionType] [varchar](50) NULL,
	[TimeoutPeriodInHours] [int] NULL,
 CONSTRAINT [PK_TransactionTypes] PRIMARY KEY CLUSTERED 
(
	[TransactionTypeId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [mmit]
GO

/****** Object:  Table [dbo].[RoleTransactiontype]    Script Date: 01/12/2012 13:43:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[RoleTransactiontype](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[RoleId] [int] NULL,
	[TransactionTypeId] [int] NULL,
	[Status] [int] NULL,
 CONSTRAINT [PK_RoleTransactiontype] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [mmit]
GO

/****** Object:  Table [dbo].[TransactionCharge]    Script Date: 01/12/2012 13:43:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[TransactionCharge](
	[TransactionChargeId] [bigint] IDENTITY(1,1) NOT NULL,
	[ChargeId] [int] NULL,
	[DebitPartyId] [int] NULL,
	[CreditPartyId] [int] NULL,
	[TransactionId] [bigint] NULL,
	[IsReversed] [int] NULL,
 CONSTRAINT [PK_TransactionCharge] PRIMARY KEY CLUSTERED 
(
	[TransactionChargeId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [mmit]
GO

/****** Object:  Table [dbo].[AccountType]    Script Date: 01/12/2012 13:43:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[AccountType](
	[AccountTypeId] [int] IDENTITY(1,1) NOT NULL,
	[Name] [varchar](max) NULL,
 CONSTRAINT [PK_AccountType] PRIMARY KEY CLUSTERED 
(
	[AccountTypeId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [mmit]
GO

/****** Object:  Table [dbo].[Customers]    Script Date: 01/12/2012 13:43:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING OFF
GO

CREATE TABLE [dbo].[Customers](
	[CustomerId] [int] IDENTITY(1,1) NOT NULL,
	[Username] [varchar](256) NULL,
	[Firstname] [varchar](256) NULL,
	[Middlename] [varchar](256) NULL,
	[Lastname] [varchar](256) NULL,
	[Mobile] [varchar](20) NULL,
	[DateCreated] [datetime] NULL,
	[CreatedBy] [varchar](256) NULL,
	[Timestamp] [datetime] NULL,
 CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED 
(
	[CustomerId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [mmit]
GO

/****** Object:  Table [dbo].[Vouchers]    Script Date: 01/12/2012 13:43:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Vouchers](
	[VoucherId] [int] IDENTITY(1,1) NOT NULL,
	[PIN] [varchar](20) NULL,
	[SerialNo] [varchar](50) NULL,
	[Value] [float] NULL,
	[IsUsed] [bit] NULL,
	[DateUsed] [datetime] NULL,
	[DateGenerated] [datetime] NULL,
	[Timestamp] [datetime] NULL,
	[AccountId] [int] NULL,
 CONSTRAINT [PK_Vouchers] PRIMARY KEY CLUSTERED 
(
	[VoucherId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Transactions]  WITH CHECK ADD  CONSTRAINT [FK_Transactions_Account] FOREIGN KEY([AuthorisationId])
REFERENCES [dbo].[Account] ([AccountId])
GO

ALTER TABLE [dbo].[Transactions] CHECK CONSTRAINT [FK_Transactions_Account]
GO

ALTER TABLE [dbo].[Transactions]  WITH CHECK ADD  CONSTRAINT [FK_Transactions_Account1] FOREIGN KEY([SenderId])
REFERENCES [dbo].[Account] ([AccountId])
GO

ALTER TABLE [dbo].[Transactions] CHECK CONSTRAINT [FK_Transactions_Account1]
GO

ALTER TABLE [dbo].[Transactions]  WITH CHECK ADD  CONSTRAINT [FK_Transactions_Account2] FOREIGN KEY([RecipientId])
REFERENCES [dbo].[Account] ([AccountId])
GO

ALTER TABLE [dbo].[Transactions] CHECK CONSTRAINT [FK_Transactions_Account2]
GO

ALTER TABLE [dbo].[Transactions]  WITH CHECK ADD  CONSTRAINT [FK_Transactions_TransactionTypes1] FOREIGN KEY([TransactionTypeId])
REFERENCES [dbo].[TransactionTypes] ([TransactionTypeId])
GO

ALTER TABLE [dbo].[Transactions] CHECK CONSTRAINT [FK_Transactions_TransactionTypes1]
GO

ALTER TABLE [dbo].[Account]  WITH CHECK ADD  CONSTRAINT [FK_Account_Customers] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[Customers] ([CustomerId])
GO

ALTER TABLE [dbo].[Account] CHECK CONSTRAINT [FK_Account_Customers]
GO

ALTER TABLE [dbo].[Rule]  WITH CHECK ADD  CONSTRAINT [FK_Rule_Account] FOREIGN KEY([TargetAccountId])
REFERENCES [dbo].[Account] ([AccountId])
GO

ALTER TABLE [dbo].[Rule] CHECK CONSTRAINT [FK_Rule_Account]
GO

ALTER TABLE [dbo].[Rule]  WITH CHECK ADD  CONSTRAINT [FK_Rule_Rule] FOREIGN KEY([TargetRoleId])
REFERENCES [dbo].[Role] ([RoleId])
GO

ALTER TABLE [dbo].[Rule] CHECK CONSTRAINT [FK_Rule_Rule]
GO

ALTER TABLE [dbo].[Rule]  WITH CHECK ADD  CONSTRAINT [FK_Rule_TransactionTypes] FOREIGN KEY([TargetTransactionTypeId])
REFERENCES [dbo].[TransactionTypes] ([TransactionTypeId])
GO

ALTER TABLE [dbo].[Rule] CHECK CONSTRAINT [FK_Rule_TransactionTypes]
GO

ALTER TABLE [dbo].[Charge]  WITH CHECK ADD  CONSTRAINT [FK_Charge_AccountType] FOREIGN KEY([AccountTypeId])
REFERENCES [dbo].[AccountType] ([AccountTypeId])
GO

ALTER TABLE [dbo].[Charge] CHECK CONSTRAINT [FK_Charge_AccountType]
GO

ALTER TABLE [dbo].[Charge]  WITH CHECK ADD  CONSTRAINT [FK_Charge_TransactionTypes] FOREIGN KEY([TransactionTypeId])
REFERENCES [dbo].[TransactionTypes] ([TransactionTypeId])
GO

ALTER TABLE [dbo].[Charge] CHECK CONSTRAINT [FK_Charge_TransactionTypes]
GO

ALTER TABLE [dbo].[RoleAccount]  WITH CHECK ADD  CONSTRAINT [FK_RoleAccount_Account] FOREIGN KEY([AccountId])
REFERENCES [dbo].[Account] ([AccountId])
GO

ALTER TABLE [dbo].[RoleAccount] CHECK CONSTRAINT [FK_RoleAccount_Account]
GO

ALTER TABLE [dbo].[RoleAccount]  WITH CHECK ADD  CONSTRAINT [FK_RoleAccount_Role] FOREIGN KEY([RoleId])
REFERENCES [dbo].[Role] ([RoleId])
GO

ALTER TABLE [dbo].[RoleAccount] CHECK CONSTRAINT [FK_RoleAccount_Role]
GO

ALTER TABLE [dbo].[RoleTransactiontype]  WITH CHECK ADD  CONSTRAINT [FK_RoleTransactiontype_Role] FOREIGN KEY([RoleId])
REFERENCES [dbo].[Role] ([RoleId])
GO

ALTER TABLE [dbo].[RoleTransactiontype] CHECK CONSTRAINT [FK_RoleTransactiontype_Role]
GO

ALTER TABLE [dbo].[RoleTransactiontype]  WITH CHECK ADD  CONSTRAINT [FK_RoleTransactiontype_TransactionTypes] FOREIGN KEY([TransactionTypeId])
REFERENCES [dbo].[TransactionTypes] ([TransactionTypeId])
GO

ALTER TABLE [dbo].[RoleTransactiontype] CHECK CONSTRAINT [FK_RoleTransactiontype_TransactionTypes]
GO

ALTER TABLE [dbo].[TransactionCharge]  WITH CHECK ADD  CONSTRAINT [FK_TransactionCharge_Account] FOREIGN KEY([CreditPartyId])
REFERENCES [dbo].[Account] ([AccountId])
GO

ALTER TABLE [dbo].[TransactionCharge] CHECK CONSTRAINT [FK_TransactionCharge_Account]
GO

ALTER TABLE [dbo].[TransactionCharge]  WITH CHECK ADD  CONSTRAINT [FK_TransactionCharge_Account1] FOREIGN KEY([DebitPartyId])
REFERENCES [dbo].[Account] ([AccountId])
GO

ALTER TABLE [dbo].[TransactionCharge] CHECK CONSTRAINT [FK_TransactionCharge_Account1]
GO

ALTER TABLE [dbo].[TransactionCharge]  WITH CHECK ADD  CONSTRAINT [FK_TransactionCharge_Transactions] FOREIGN KEY([TransactionId])
REFERENCES [dbo].[Transactions] ([TransactionId])
GO

ALTER TABLE [dbo].[TransactionCharge] CHECK CONSTRAINT [FK_TransactionCharge_Transactions]
GO

ALTER TABLE [dbo].[Vouchers]  WITH CHECK ADD  CONSTRAINT [FK_Vouchers_Account] FOREIGN KEY([AccountId])
REFERENCES [dbo].[Account] ([AccountId])
GO

ALTER TABLE [dbo].[Vouchers] CHECK CONSTRAINT [FK_Vouchers_Account]
GO


